package forms;

import helpers.DateHelper;
import helpers.StringHelper;
import helpers.ValidateHelper;

import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import models.CooperationModel;


public class CooperationForm {
	public TreeMap checkValid(HttpServletRequest request, CooperationModel cooperation) {
		TreeMap form = new TreeMap();
		TreeMap check = new TreeMap();

		String name = (String) request.getParameter("name");
		String email = (String) request.getParameter("email");
		String city = (String) request.getParameter("city");
		String phone = (String) request.getParameter("phone");
		String company = (String) request.getParameter("company");
		String address = (String) request.getParameter("address");
		String content = (String) request.getParameter("content");
		
		if (name == null || name.isEmpty()) {
			check.put("name", "Vui lòng nhập \" <strong>Tên</strong> \"");
			cooperation.setName("");
		} else {
			cooperation.setName(name);
		}
		
		if (email == null || email.isEmpty()) {
			check.put("email", "Vui lòng nhập \" <strong>Email</strong> \"");
			cooperation.setEmail("");
		} else if (!ValidateHelper.isEmail(email)) {
			check.put("email", "Địa chỉ \" <strong>Email</strong> \" không đúng.");
			cooperation.setEmail(email);
		} else {
			cooperation.setEmail(email);
		}
		
		if (city == null || city.isEmpty()) {
			check.put("city", "Vui lòng nhập \" <strong>Khu vực</strong> \"");
			cooperation.setCity("");
		} else {
			cooperation.setCity(city);
		}
		
		if (phone == null || phone.isEmpty()) {
			check.put("phone", "Vui lòng nhập \" <strong>Số ĐT</strong> \"");
			cooperation.setPhone("");
		} else {
			cooperation.setPhone(phone);
		}
		
		if (company == null || company.isEmpty()) {
			check.put("company", "Vui lòng nhập \" <strong>tên công ty</strong> \"");
			cooperation.setCompany("");
		} else {
			cooperation.setCompany(company);
		}
		
		if (address == null || address.isEmpty()) {
			check.put("address", "Vui lòng nhập \" <strong>địa chỉ</strong> \"");
			cooperation.setAddress("");
		} else {
			cooperation.setAddress(address);
		}
		
		if (content == null || content.isEmpty()) {
			check.put("content", "Vui lòng nhập \" <strong>Nội dung liên hệ</strong> \"");
			cooperation.setContent("");
		} else {
			cooperation.setContent(content);
		}

		form.put("checkValid", check);
		form.put("cooperation", cooperation);

		return form;
	}
}
